package app

import (
	"context"

	v1 "gitee.com/liangziyisheng/caas-platform-mc/api/app/v1"

	"gitee.com/liangziyisheng/caas-platform-mc/internal/service"
)

func (c *ControllerV1) Info(ctx context.Context, req *v1.InfoReq) (res *v1.InfoRes, err error) {
	res = &v1.InfoRes{Id: req.Id}
	out, err := service.App().Info(ctx, &v1.InfoInput{Id: req.Id})
	if err != nil {
		return nil, err
	}
	res.Name = out.Name
	res.Type = out.Type
	res.Description = out.Description
	for _, v := range out.Menus {
		t := v1.Menu{
			Id:          v.Id,
			Name:        v.Name,
			Type:        v.Type,
			Description: v.Description,
		}
		res.Menus = append(res.Menus, t)
	}
	for _, v := range out.Components {
		t := v1.Component{
			Id:          v.Id,
			Name:        v.Name,
			Description: v.Description,
		}
		res.Components = append(res.Components, t)
	}

	return res, nil
}
